
import requests


from apis.login import Login
from common.base import Base


# 新增日志
class Log(Base):
    token=""

    def __init__(self,t):
        self.token=t
        self.header={"Admin-Token":self.token}
        self.ip = self.i

    def addlog(self,a="/OaLog/addOrUpdate",b={"categoryId": "1","content": "这里是今日内容~~","tomorrow": "这里明日工作计划~","question": "这里是今日遇到的问题","batchId":"bid","sendUserIds": "3,4","sendDeptIds": "","customerIds": "","contactsIds": "","businessIds": "","contractIds": ""}):

        uri = a
        url = f"{self.ip}{uri}"
        myjson = b
        s=requests.post(url,json=myjson,headers=self.header)
        print(s.json())
        return s

    # 修改日志
    def updatelog(self,c="/OaLog/addOrUpdate",d={"logId":5,"categoryId":"1","content":"这里是今日内容的修改~~","tomorrow":"这里明日工作计划的修改~","question":"这里是今日遇到的问题的修改","batchId":"a6522a16cc407ef091adb0b1a9a93949","sendUserIds":"3,4","sendDeptIds":"","customerIds":"","contactsIds":"","businessIds":"","contractIds":""}):

        uri1=c
        url1 = f"{self.ip}{uri1}"
        myjson1=d
        s1=requests.post(url1,json=myjson1,headers=self.header)
        print(s1.json())
        return s1

    # 获取日志
    def getlog(self):
        uri2 = f"{self.ipa}/OaLog/queryList"
        myjson2={"page": 1,"limit": 5,"by": "1"}
        s2=requests.post(uri2,json=myjson2,headers=self.header)
        print(s2.json())
        return s2

    # 删除日志
    def deletelog(self):
        uri3=f"{self.ipa}/OaLog/deleteById"
        mydata={"logId":4}
        s3=requests.post(uri3,data=mydata,headers=self.header)
        print(s3.json())
        return s3

    # 文件上传
    def text(self):
        ipa="http://172.16.0.254:8080"
        fileurl = f"{ipa}/file/upload"
        fdata = {"type": "img"}
        ffile = {"file":
                     ('11.jpg',
                      open(r'D:\work\pythonProject\Apitest\datas\11.jpg', 'rb'), 'image/png')}
        e = requests.post(fileurl, data=fdata, files=ffile, headers=self.header)
        print(e.json())
        return e


if __name__ =='__main__':
    a=Login().gettoken()
    b=Log(a)
    b.addlog()
    b.updatelog()
    # b.getlog()
    # b.deletelog()



